//
//  WEIBOUserTool.m
//  OneWeiBo
//
//  Created on 22.
//   
//

#import "WEIBOUserTool.h"
#import "WEIBOUser.h"
#import "WEIBOAccount.h"
#import "WEIBOAccountTool.h"
#import "WEIBOHttpTool.h"
#import "MJExtension.h"

@implementation WEIBOUserTool
+ (void)userDataWithSuccess:(void (^)(WEIBOUser *))success failure:(void (^)(NSError *))failure
{
    // 封装参数请求
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"access_token"] = [WEIBOAccountTool account].access_token;
    params[@"uid"] = @([WEIBOAccountTool account].uid);
    
    // 发送请求
    [WEIBOHttpTool getWithURL:@"https://api.weibo.com/2/users/show.json" params:params success:^(id json) {
        //WEIBOLog(@"加载home_timeline成功：%@",json);
        // 将字典数组转为模型数组
        WEIBOUser *user = [WEIBOUser objectWithKeyValues:json];
        
        if (success) {
            success(user);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}
@end
